1. Field of the Invention
The present invention relates to garbage collection in a virtualized environment, and more specifically, to a method and system for garbage collection in which extra memory is allocated and merged into program space.
2. Description of Related Art
Currently, the virtualization technology has been widely applied. The virtualization technology provides a mode that can accommodate a plurality of virtual machines (VM) in a large server, which reduces the overall cost for the user and improves the reliability and flexibility of the application, thereby reducing the possibility that the user excessively provides computing resources for some workload spikes. The virtualization technology helps to isolate important applications, whereby different applications operating on different virtual machines will not share the operating system. Accordingly, a fatal breakdown caused by applications will not influence the application in other virtual machines. The virtualization technology is an important and basic technology in “Cloud Computing” technology. Around the world, more and more individuals and organizations are using virtualization solution to provide “Cloud Environment” service so as to obtain the benefits of improving the utilization efficiency and flexibility of computer hardware, and reducing the hardware cost.
Garbage collection is a memory management mechanism that the program executing environment (such as java, C# and most of the scripting languages) automatically collects the unused memory. A garbage collector is an important composite part of the virtual machine. Take JVM (Java Virtual Machine) as an example, when there is too small free memory space managed by the JVM or too small continuous free memory space, and the JVM cannot assign a memory space for an object from the Heap, the JVM will issue a message indicating a wrong memory assignment, thereby activating the garbage collector to perform garbage collection. When the garbage collector performs garbage collection, it checks objects that are no longer used by the application program in the heap and performs a necessary operation to collect the memory occupied by them. The garbage collection tactics generally include a mark-copy method and a mark-sweep method. In the mark-copy method, the Java virtual machine divides the managed memory space into two parts. When half of one part of memory space is used, the garbage collection process will copy all live objects to the other half of unused memory space, and continue to assign the memory on the other half space. The former half of the space converts into free space as a target space for the next garbage collection. However, the mark-copy method requires that a half of the memory space managed by the virtual machine must be saved which means the memory usage rate will not exceed 50%. In the mark-sweep method, the operating process can be divided into three phases: marking phase, sweeping phase, and compressing phase. The task of the marking phase is traversing all the directed objects from a root node of the objects, and adding a mark to all the live objects being found until the traversing is completed. Objects which are not marked are garbage. All the garbage is collected in the sweeping phase. Finally, in the compressing phase, the objects distributed discretely and disorderly are placed in a continuous address in the memory. Although the compressing phase is not initiated in each garbage collection, the time consumed in one compressing phase is usually several seconds. During this period, the application execution stops. Since the application of a server terminal is widely operated on the virtual machine, a cloud computing platform as a server terminal needs to process a large amount of application requests and needs to ensure the service quality. The service quality of the server terminal application requires the response time for processing the requests to be in a millisecond order. Therefore, the response delay introduced by the virtual machine in the compressing phase in the garbage collection is unacceptable, and should be avoided.
Since the response delay increase caused by the mark-sweep method is unacceptable, and a traditional mark-copy method causes a too low memory utilization rate (no more than 50%), and the memory in the virtualized platform is a key valuable resource, a garbage collection method that improves the memory usage efficiency in a virtualization environment is needed to meet the requirement of the long time operating program at the server terminal on the response time of the service request.